gtk-demo: Improve the font rendering demo
authorMatthias Clasen <mclasen@redhat.com>
Fri, 3 Sep 2021 04:19:17 +0000 (00:19 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 3 Sep 2021 15:29:44 +0000 (11:29 -0400)
Add a toggle for antialiasing, and make the metrics
hinting turn on rounding of positions, to match what
we do with settings now.

demos/gtk-demo/fontrendering.c
demos/gtk-demo/fontrendering.ui

index 005f3637c6184a9496d1c48400f2c39de2f47392..e95a78f7e73340974e868e90cf6b8fe33884b3b8 100644 (file)
@@ -10,6 +10,7 @@ static GtkWidget *font_button = NULL;
 static GtkWidget *entry = NULL;
 static GtkWidget *image = NULL;
 static GtkWidget *hinting = NULL;
+static GtkWidget *anti_alias = NULL;
 static GtkWidget *hint_metrics = NULL;
 static GtkWidget *up_button = NULL;
 static GtkWidget *down_button = NULL;
@@ -37,6 +38,7 @@ update_image (void)
   cairo_font_options_t *fopt;
   cairo_hint_style_t hintstyle;
   cairo_hint_metrics_t hintmetrics;
+  cairo_antialias_t antialias;
 
   if (!context)
     context = gtk_widget_create_pango_context (image);
@@ -65,6 +67,13 @@ update_image (void)
     hintmetrics = CAIRO_HINT_METRICS_OFF;
   cairo_font_options_set_hint_metrics (fopt, hintmetrics);
 
+  if (gtk_check_button_get_active (GTK_CHECK_BUTTON (anti_alias)))
+    antialias = CAIRO_ANTIALIAS_GRAY;
+  else
+    antialias = CAIRO_ANTIALIAS_NONE;
+  cairo_font_options_set_antialias (fopt, antialias);
+
+  pango_context_set_round_glyph_positions (context, hintmetrics == CAIRO_HINT_METRICS_ON);
   pango_cairo_context_set_font_options (context, fopt);
   cairo_font_options_destroy (fopt);
   pango_context_changed (context);
@@ -252,6 +261,7 @@ do_fontrendering (GtkWidget *do_widget)
       entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry"));
       image = GTK_WIDGET (gtk_builder_get_object (builder, "image"));
       hinting = GTK_WIDGET (gtk_builder_get_object (builder, "hinting"));
+      anti_alias = GTK_WIDGET (gtk_builder_get_object (builder, "antialias"));
       hint_metrics = GTK_WIDGET (gtk_builder_get_object (builder, "hint_metrics"));
       text_radio = GTK_WIDGET (gtk_builder_get_object (builder, "text_radio"));
       show_grid = GTK_WIDGET (gtk_builder_get_object (builder, "show_grid"));
@@ -262,6 +272,7 @@ do_fontrendering (GtkWidget *do_widget)
       g_signal_connect (entry, "notify::text", G_CALLBACK (update_image), NULL);
       g_signal_connect (font_button, "notify::font-desc", G_CALLBACK (update_image), NULL);
       g_signal_connect (hinting, "notify::active", G_CALLBACK (update_image), NULL);
+      g_signal_connect (anti_alias, "notify::active", G_CALLBACK (update_image), NULL);
       g_signal_connect (hint_metrics, "notify::active", G_CALLBACK (update_image), NULL);
       g_signal_connect (text_radio, "notify::active", G_CALLBACK (update_image), NULL);
       g_signal_connect (show_grid, "notify::active", G_CALLBACK (update_image), NULL);
index 363f6f5e3df4c6266e4f269739afe38170a495a7..fc7a9fed4a723cd5e02300f4097e98c390d3cbd8 100644 (file)
                 </layout>
               </object>
             </child>
+            <child>
+              <object class="GtkCheckButton" id="antialias">
+                <property name="label">Antialias</property>
+                <layout>
+                  <property name="column">3</property>
+                  <property name="row">1</property>
+                </layout>
+              </object>
+            </child>
             <child>
               <object class="GtkComboBoxText" id="hinting">
                 <property name="active">0</property>